package complex.java.img;

import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class ImgTest {

    public static void main(String[] args) {
        try {
            //需要考虑图片类型
            
            // 操作的原图-->读入缓冲
            File picFile = new File(
                                    "D:/work/project/own/complex/complex.java/src/main/java/complex/java/img/ferret.jpg");
            BufferedImage src = ImageIO.read(picFile);

            // 截取小图
            int x1 = 141;
            int y1 = 62;
            int x2 = 344;
            int y2 = 265;
            BufferedImage target = src.getSubimage(x1, y1, x2 - x1, y2 - y1);

            // 缩放到想要的大小(rize返回BufferedImage)
            target = ResizeImg.rize(target, 100, 100);

            // 写入新文件
            File file1 = new File(
                                  "D:/work/project/own/complex/complex.java/src/main/java/complex/java/img/ferret1.jpg");
            ImageIO.write(target, "jpg", file1);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
